package cn.net.wanji.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MultipartException;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MultipartException.class)
    public ResponseEntity<String> handleMultipartException(MultipartException ex) {
        log.info("文件上传失败原因: {}, 失败信息：{}", ex.getCause(), ex.getMessage());
        return new ResponseEntity<>("文件上传失败：" + ex.getMessage(), HttpStatus.BAD_REQUEST);
    }

}
